Page({
    data: {
        previewHidden: !0,
        repaymentDetail: []
    },
    onLoad: function(e) {
        var t = this, a = new Promise(function(e, t) {
            wx.getImageInfo({
                src: "../../images/bg.jpg",
                success: function(t) {
                    console.log(t), e(t);
                }
            });
        });
        Promise.all([ a ]).then(function(e) {
            console.log(e);
            var a = wx.createCanvasContext("shareImg"), o = [ 1e3, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 1110, 1120, 1130, 1140, 1150, 1160, 1170, 1180, 1190, 1200, 1210, 1220, 1230, 1240, 1250, 1260, 1270, 1280, 1290, 1300, 1310, 1320, 1330, 1340, 1350, 1360, 1370, 1380, 1390, 1400, 1410, 1420, 1430, 1440, 1450, 1460, 1470, 1480, 1490, 1500, 1510, 1520, 1530, 1540, 1550, 1560, 1570, 1580, 1590, 1600, 1610, 1620, 1630, 1640, 1650, 1660, 1670, 1680, 1690, 1700, 1710, 1720, 1730, 1740, 1750, 1760, 1770, 1780, 1790, 1800, 1810, 1820, 1830, 1840, 1850, 1860, 1870, 1880, 1890, 1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2e3 ], s = 25 * o.length + 90;
            console.log("h", s), a.drawImage("../../" + e[0].path, 0, 0, 375, s), a.setFillStyle("#ffffff"), 
            a.setFontSize(18), t.setData({
                repaymentDetail: o,
                h: s,
                hh: s + 30
            });
            for (var n = 0; n < o.length; n++) {
                var i = n + 1;
                a.fillText("第" + i + "月还款额: " + o[n] + "元", 100, 70 + 25 * n);
            }
            a.stroke(), a.draw();
        });
    },
    share: function() {
        var e = this;
        wx.showLoading({
            title: "努力生成中..."
        }), wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: 375,
            height: this.data.h,
            destWidth: 375,
            destHeight: this.data.h,
            canvasId: "shareImg",
            success: function(t) {
                console.log(t.tempFilePath), e.setData({
                    preurl: t.tempFilePath,
                    previewHidden: !1
                }), wx.hideLoading();
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    save: function() {
        var e = this;
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] ? e.startSaveImage() : wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        e.startSaveImage();
                    }
                });
            }
        });
    },
    startSaveImage: function() {
        var e = this;
        wx.saveImageToPhotosAlbum({
            filePath: e.data.preurl,
            success: function(t) {
                wx.showModal({
                    content: "图片已保存到相册，赶紧晒一下吧~",
                    showCancel: !1,
                    confirmText: "好哒",
                    confirmColor: "#72B9C3",
                    success: function(t) {
                        t.confirm && (console.log("用户点击确定"), e.setData({
                            previewHidden: !0
                        }));
                    }
                });
            }
        });
    }
});